<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        h1{
            display: none;
        }
    </style>
</head>
<body>
    <h1 class="login">欢迎 <span>xx</span>  来到千锋</h1>
    <h1 class="noLogin"><a href="">登录</a><a href="">注册</a></h1>

    <script>

        const oLogin = document.querySelector('.login') ;
        const oSpan = oLogin.querySelector('span') ;
        const oNoLogin = document.querySelector('.noLogin') ;

        // 获取cookie
        const cookies = document.cookie ;
        let arr = cookies.split('; ') ;
        arr = arr.map( v => {
            const arr2 = v.split('=') ;
            return {
                username : arr2[0] ,
                userpwd : arr2[1]
            }
        })
        console.log(arr);

        const res = arr.filter( v=> {
            return v.username === 'login_user'
        })[0] ;

        if(res) {
            oLogin.style.display = 'block' ;
            oSpan.innerHTML = res.userpwd ;
        } else {
            oNoLogin.style.display = 'block'
        }
        
        

    </script>
</body>
</html>